<!DOCTYPE html>
<html lang="en">
<head>
    <title>添加保险类别</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script src="/js/vue/vue.min.js"></script>
    <script src="/js/layer/layer.js" charset="utf-8"></script>
    <style>
        select.error, input.error {
            border: 1px solid red;
        }
    </style>
</head>
<body>
<section id="container">
<#include "sider.ftl">  <#--引入头部和导航栏-->
    <section id="main-content">
        <section class="wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <section class="panel">
                        <header class="panel-heading">
                            添加保险
                        </header>
                        <div class="panel-body">
                            <div class="form">
                                <form class="cmxform form-horizontal" id="addInsurcateForm">
                                    <div class="form-group ">
                                        <label for="insurcateName" class="control-label col-lg-3">保险名称</label>
                                        <div class="col-lg-6">
                                            <input class=" form-control" id="insurcateName" name="insurname" type="text">
                                        </div>
                                    </div>
                                    <div class="form-group ">
                                        <label for="insurType" class="control-label col-lg-3">保险类别</label>
                                        <div class="col-lg-6">
                                            <input class=" form-control" id="insurType" name="insurtype" type="text">
                                        </div>
                                    </div>
                                    <div class="form-group ">
                                        <label for="comrate" class="control-label col-lg-3">保险赔率</label>
                                        <div class="col-lg-6">
                                            <input class=" form-control" id="comrate" name="comrate" type="text">
                                        </div>
                                    </div>
                                    <div class="form-group ">
                                        <label for="maxinsur" class="control-label col-lg-3">最大保险金额</label>
                                        <div class="col-lg-6">
                                            <input class=" form-control" id="maxinsur" name="maxinsur" type="text">
                                        </div>
                                    </div>
                                    <div class="form-group ">
                                        <label for="mininsur" class="control-label col-lg-3">最低保险金额</label>
                                        <div class="col-lg-6">
                                            <input class=" form-control" id="mininsur" name="mininsur" type="text">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-lg-offset-3 col-lg-6">
                                            <button class="btn btn-primary" type="button" id="referBut">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
            </div>
        </section>
    <#include "/foot.html"><#--引入底部-->
    </section>
</section>
</body>
</html>
<script>
    var addInsurcate = function () {
        $.ajax({
            url: "/insurcate/toAddInsurcateAfter.do",
            type: "post",
            data: $("#addInsurcateForm").serialize(),
            success: function () {
                layer.msg('添加成功', {icon: 6});
            }
        });
    };
    var check = function () {
        jQuery.validator.addMethod("regex", function (value, element, params) {
            var exp = new RegExp(params);
            return exp.test(value);
        }, "格式错误");
        return $("#addInsurcateForm").validate({
            rules: {
                insurname: {
                    required: true,
                    rangelength: [4, 11]
                },
                insurtype: {
                    required: true,
                    rangelength: [3, 10]
                },

                comrate: {
                    required: true,
                    regex: "^0\\.[1-9]\\d*$"
                },
                maxinsur: {
                    required: true,
                    regex:"(^[1-9][0-9]{4,5}$)"
                },
                mininsur: {
                    required: true,
                    regex:"(^[1-4][0-9]{3,3}$)|(^[5-9][0-9]{2,2}$)"
                }
            },
            messages: {
                insurcateName: {
                    required: "",
                    rangelength: "保险名称长度在4-11之间"
                },
                insurType: {
                    required: "",
                    rangelength: "保险类别长度在3-10之间"
                },
                comrate: {
                    required: "",
                    regex: "保险赔率必须小于1,大于0"
                },
                maxinsur: {
                    required: "",
                    regex: "最大投保金额必须大于最小投保金额,且在1万-100万以内"
                },
                mininsur: {
                    required: "",
                    regex:"必须小于最大投保金额且不能超过5000,不能小于500"
                }
            }
        });
    };
    /*提交表单的点击事件*/
    $("#referBut").click(function () {
        /*ignore: ":hidden:not(select)";//解决无法校验select*/
        $("#referBut").submit();//button按钮变为submit
        addInsurcate();
    });
    /*$("#cancelBut").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });*/
    $("#addInsurcateForm").mouseenter(function () {
        if (!check().form()) {
            return;
        }
    });
</script>